/**
 * Created by huangying on 16/10/12.
 */
var article_id_details = '';
var _id = "";
var img_link = "";
var img_width = "";//图片宽度
var img_height = "";//图片高度
var div_width = "";//外框div宽度
var div_height = "";//外框div高度
var img_src = "";

var reply_type = "";//回复类型:0:评论文章,1:对评论回复

$(document).ready(function () {
    article_id_details = location.search; //获取url中"?"符后的字串
    if (article_id_details != '') {
        //分享后会带这个参数
        var article_id_details_share = article_id_details.indexOf('from');

        if (article_id_details_share == -1) {
            article_id_details = article_id_details.substring(12, article_id_details.length);
        } else {
            article_id_details = article_id_details.substring(12, article_id_details_share - 1);
        }

        //文章页面展示
        article_details();

        //收到的礼物打赏
        gift_show();

        //打赏排行榜
        rank_gift();

        //用户的金币数展示
        user_gold();

        //热门评论(页面刷新 or 进入页面时加载,确保是否存在user_id)
        article_comments_hot_first();

        //全部评论(页面刷新 or 进入页面时加载,确保是否存在user_id)
        article_comments_all_first();

        //相关推荐
        about_read();

        if (user_id) {
            $('.thread-side-bar .praise').show();
            $('.thread-side-bar .collect').show();
            $('.thread-side-bar .report').show();
            $('.pubcomment').show();
            $('.no-login-comment-box').hide();
        }

        $('.loading').hide();
    } else {
        $('.article_content').html("<h2 class='none_info' style='margin:0;padding: 135px 274px;'>暂时没有相关内容</h2>")
        $('.article_content').css("margin-bottom", "30px");
        //个人信息
        $('.user-info').hide();
        //相关阅读
        $('.related-thread').hide();

    }
});

window.onload = function () {
    //图片修改为canvas
    $('.img_link').each(function (i, item) {
        var _i = i + 1;
        img_link = $(this).children('.image_show');

        var img_url_show = img_link.attr('src');

        var mycanvas = document.createElement('canvas');
        document.getElementById('img_change_canvas_' + _i).appendChild(mycanvas);
        document.getElementById('img_change_canvas_' + _i).setAttribute('data-url', img_url_show);

        img_width = img_link.css('width');//图片宽度
        img_width = img_width.substring(0, img_width.length - 2);

        img_height = img_link.css('height');//图片高度
        img_height = img_height.substring(0, img_height.length - 2);

        mycanvas.width = img_width;//canvas的宽度
        mycanvas.height = img_height;//canvas的高度

        img_src = img_link.attr('src');

        change_canvas(mycanvas);

        img_link.remove();

        $('.loading').hide();
    });


}


//具体文章页面展示
function article_details() {
    $.ajax({
        type: 'GET',
        url: url_link + 'articles/' + article_id_details,
        data: {
            user_id: user_id
        },
        async: false,
        success: function (data) {
            try {
                var obj = JSON.parse(data);
                var img_num = 0;
                //获取文章作者的id
                $('.report-btn').attr('data-report-person-user-id', obj.data.user.user_id);
                target_user_id = obj.data.user.user_id;
                //文章详情
                var articles_detail = "";
                //作者信息(头像,昵称,性别)
                var author_info_head = "";
                //作者信息(粉丝,关注,作品)
                var author_info_home = "";
                //关注,发私信按钮
                var button_info = "";
                if (obj.code == 0) {
                    //=================================显示点赞总数=================================//
                    $('.praise-thread-btn').append(obj.data.like_count);
                    if (obj.data.has_like == 1) {
                        //已点赞
                        $('.praise-thread-btn').addClass('has-like');
                        $('.praise-thread-btn').removeClass('no-like')
                    } else {
                        $('.praise-thread-btn').addClass('no-like');
                        $('.praise-thread-btn').removeClass('has-like')
                    }
                    //=================================文章详情=================================//
                    articles_detail += "<h2>";
                    if (obj.data.is_nice == 1) {
                        articles_detail += "<i class='essence-mark'></i>"
                    }
                    articles_detail += obj.data.title + "</h2>" +
                        "<div class='thread-info'>" +
                        "<div class='interest'>" +
                        "<em class='ico'></em>" +
                        "<a href='../discover_theme.html?mototype_id=" + obj.data.mototype_id + "'>" + obj.data.mototype_name + "</a>"
                    if (is_admin == 1) {
                        articles_detail += "<span class='change change_theme'><i></i><i></i><i></i></span>" +
                            "<a style='color: red;font-weight: bold;' class='change_theme'>修改主题</a>" +
                            "<ul class='interest-list interest-list-theme'></ul>" +
                            "<span class='change change_mototype'><i></i><i></i><i></i></span>" +
                            "<a style='color: red;font-weight: bold;' class='change_mototype'>修改车型</a>" +
                            "<ul class='interest-list interest-list-mototype' style='left: 140px;'></ul>" +
                            "<div class='interest-label-list'></div> "
                    }
                    articles_detail += "</div>";
                    if (user_id == obj.data.user_id || is_admin == 1) {
                        articles_detail += "<span class='delete-article' data-id=" + obj.data.user_id + ">删除本文</span>"
                    }
                    articles_detail += "<span class='click-count'><i></i>" + obj.data.see_count + "</span>" +
                        "<span class='publish-time'>" + obj.data.createdDate + "</span>" +
                        "</div>";
                    var _content = obj.data.content.split("$$##MotorTravel##$$");
                    for (var i = 0; i < _content.length; i++) {
                        var n = _content[i].substring(0, 12);
                        var m = _content[i].substring(0, 13);
                        if (n == "$$##Text##$$") {
                            //纯文字
                            articles_detail += "<p class='thread-model-txt'>" + _content[i].substring(12, _content[i].length) + "</p>"
                        } else if (m == "$$##Image##$$") {
                            //图
                            var _content_image_description = _content[i].split("$$##ImageDescription##$$");
                            var _content_image_url = _content_image_description[0].split("$$##ImageInfo##$$");
                            articles_detail += "<div class='thread-model'>" +
                                "<div class='img-box' style='width: 100%'>" +
                                "<a href='javascript:;' class='thread-image-comment-btn'>图片评论<span></span></a>"
                            for (var a = 0; a < _content_image_description.length; a++) {
                                if (a == 0) {
                                    img_num = img_num + 1;
                                    articles_detail += "<a style='display:inline-block' class='img_link' id='img_change_canvas_" + img_num + "'>" +
                                        "<img src=" + _content_image_url[a].substring(13, _content_image_url[0].length) + " class='upload image_show' style='display: inline-block;width: 100%;'>" +
                                        "</a></div>"
                                } else if (a == 1) {
                                    articles_detail += "<div class='description'><p>" + _content_image_description[a] + "</p></div>"
                                }

                            }
                            articles_detail += "</div>"
                        } else if (m == "$$##Video##$$") {
                            //视频
                            var _content_video_description = _content[i].split("$$##VideoDescription##$$");
                            articles_detail += "<div class='thread-model'><div class='img-box' style='width: 100%'>";
                            for (var b = 0; b < _content_video_description.length; b++) {
                                if (b == 0) {
                                    articles_detail += "<a href=" + _content_video_description[b].substring(13, _content_video_description[b].length) + " style='display:inline-block' target='_blank'>" +
                                        "<video src=" + _content_video_description[b].substring(13, _content_video_description[b].length) + " class='upload' style='display: inline-block;width: 100%;' controls='controls'>" +
                                        "</a>" +
                                        "</div>"
                                } else if (b == 1) {
                                    articles_detail += "<div class='description'><p>" + _content_video_description[b] + "</p></div>"
                                }
                            }
                            articles_detail += "</div>"
                        }
                    }
                    articles_detail += "<div class='thread-modify-time'>" +
                        "[ 本帖最后由 <a>" + obj.data.user.nickname + " </a>于 " + obj.data.createdDate + " 修改 ]" +
                        "</div>" +
                        "<div class='interest-share'>" +
                        "<div class='interest'>" +
                        "发现类别:" +
                        "<a href='../discover_theme.html?mototype_id=" + obj.data.mototype_id + "' target='_blank'>" + obj.data.mototype_name + "</a>" +
                        "</div>" +
                            //"<div class='share bdsharebuttonbox bdshare-button-style1-32'>" +
                            //"<span>分享到：</span>" +
                            //"<a href='#' class='bds_weixin' data-cmd='weixin' title='分享到微信'></a>" +
                            //"<a href='#' class='bds_tsina' data-cmd='tsina' title='分享到新浪微博'></a>" +
                            //"<a href='#' class='bds_sqq' data-cmd='sqq' title='分享到QQ好友'></a>" +
                            //"<a href='#' class='bds_qzone' data-cmd='qzone' title='分享到QQ空间'></a>" +
                            //"</div>" +
                        "</div>";

                    //=================================作者信息(头像,昵称,性别)=================================//
                    author_info_head += "<div class='headpic_img'>";
                    if (user_id) {
                        if (user_id == obj.data.user.user_id) {
                            //自己的作品
                            author_info_head += "<a href='../center/home.html' target='_blank'>"
                        } else {
                            author_info_head += "<a href='../lookat/article.html?user_id=" + obj.data.user.user_id + "' target='_blank'>"
                        }
                    } else {
                        author_info_head += "<a href='../loading.html' target='_blank'>"
                    }
                    if (!obj.data.user.avatar) {
                        author_info_head += "<img src='../../image/base/none.png'></a>"
                    } else {
                        author_info_head += "<img src=" + obj.data.user.avatar + "></a>"
                    }
                    if (obj.data.user.sex == 1) {
                        author_info_head += "<b class='male'></b></div>"
                    } else {
                        author_info_head += "<b class='female'></b></div>"
                    }
                    if (user_id) {
                        if (user_id == obj.data.user.user_id) {
                            //自己的作品
                            author_info_head += "<a href='../center/home.html' target='_blank'>"
                        } else {
                            author_info_head += "<a href='../lookat/article.html?user_id=" + obj.data.user.user_id + "' target='_blank'>"
                        }
                    } else {
                        author_info_head += "<a href='../loading.html' target='_blank'>"
                    }

                    author_info_head += "<em>" + obj.data.user.nickname + "</em></a>";

                    //=================================作者信息(粉丝,关注,作品)=================================//
                    if (user_id) {
                        if (user_id == obj.data.user.user_id) {
                            //自己的作品
                            author_info_home += "<li>关注<a href='../center/friend.html' target='_blank'>" + obj.data.user.follow_count + "</a></li>" +
                                "<span class='line'></span>" +
                                "<li>粉丝<a href='../center/fans.html' target='_blank'>" + obj.data.user.fans_count + "</a></li>" +
                                "<span class='line'></span>" +
                                "<li>作品<a href='../center/thread.html' target='_blank'>" + obj.data.user.article_count + "</a></li>";
                        } else {
                            author_info_home += "<li>关注<a href='../lookat/friend.html?user_id=" + obj.data.user.user_id + "'' target='_blank'>" + obj.data.user.follow_count + "</a></li>" +
                                "<span class='line'></span>" +
                                "<li>粉丝<a href='../lookat/fans.html?user_id=" + obj.data.user.user_id + "'' target='_blank'>" + obj.data.user.fans_count + "</a></li>" +
                                "<span class='line'></span>" +
                                "<li>作品<a href='../lookat/article.html?user_id=" + obj.data.user.user_id + "'' target='_blank'>" + obj.data.user.article_count + "</a></li>";
                            if (obj.data.user.has_black == 1) {
                                //已被拉黑
                                button_info += "<a href='javascript:;' class='white-button removed-blacklist-btn'><i></i>此人被您拉黑</a>";
                            } else {
                                if (obj.data.user.has_follow == 1) {
                                    //已关注
                                    button_info += "<a href='javascript:;' class='white-button un-follow-btn' id='pay_attention_button' data-user-id=" + user_id + " data-target-id=" + obj.data.user.user_id + "><i></i>取消关注</a>"
                                } else {
                                    button_info += "<a href='javascript:;' class='white-button follow-btn' id='pay_attention_button' data-user-id=" + user_id + " data-target-id=" + obj.data.user.user_id + "><i></i>关注</a>"
                                }
                            }
                            button_info += "<a href='javascript:;' class='white-button private-btn message-button' id='private_letter_button'><i></i>发私信</a>"

                        }
                    } else {
                        author_info_home += "<li>关注<a href='../loading.html' target='_blank'>" + obj.data.user.follow_count + "</a></li>" +
                            "<span class='line'></span>" +
                            "<li>粉丝<a href='../loading.html' target='_blank'>" + obj.data.user.fans_count + "</a></li>" +
                            "<span class='line'></span>" +
                            "<li>作品<a href='../loading.html' target='_blank'>" + obj.data.user.article_count + "</a></li>";
                    }


                    //=================================左侧信息栏=================================//
                    if (obj.data.has_save == 1) {
                        //已收藏
                        $('.collect a').removeClass('add-favorite');
                        $('.collect a').addClass('has-favorite');
                    } else {
                        $('.collect a').addClass('add-favorite');
                        $('.collect a').removeClass('has-favorite');
                    }


                    $('.article_content').html(articles_detail);
                    $('.headpic_info').html(author_info_head);
                    $('.user-info ul').html(author_info_home);
                    $('.button-area').html(button_info);
                } else {

                }
            } catch (e) {
                layer.msg(data.msg, {time: 3000})
            }
        }
    })
}


//相关阅读,内容获取
function about_read() {
    $.ajax({
        type: 'GET',
        url: url_link + 'articles/likely',
        data: {
            article_id: article_id_details
        },
        async: false,
        success: function (data) {
            try {
                var obj = JSON.parse(data);
                var about_read = "";
                if (obj.code == 0) {
                    if (obj.data.length != 0) {
                        $.each(obj.data, function (i, item) {
                            about_read += "<li>" +
                                "<div class='img-box'>" +
                                "<a href='show.html?article_id=" + item.article_id + "' target='_blank'>";
                            if(item.cover){
                                about_read += "<img src=" + item.cover + ">";
                            }else{
                                var _content = item.content.split("$$##MotorTravel##$$");
                                var _count = 0;
                                for (var _a = 0; _a < _content.length; _a++) {
                                    var m = _content[_a].substring(0, 13);
                                    if (m == "$$##Image##$$") {
                                        //有图
                                        _count = 1;
                                        var _content_image_description = _content[_a].split("$$##ImageDescription##$$");
                                        var _content_image_url = _content_image_description[0].split("$$##ImageInfo##$$");
                                        about_read += "<img src=" + _content_image_url[0].substring(13, _content_image_url[0].length) + ">";
                                        break;
                                    }
                                }
                                //纯文字,没有图的情况下,使用备用图片
                                if (_count == 0) {
                                    about_read += "<img src='../../image/base/none_img.png'>"
                                }
                            }
                            about_read += "</a>" +
                                "</div>" +
                                "<div class='title'>" +
                                "<a href='show.html?article_id=" + item.article_id + "' target='_blank'>" + item.title + "</a>" +
                                "</div>" +
                                "</li>"
                        });
                        $('.picList').html(about_read);
                        //相关阅读,滑动
                        $(".picScroll-left").slide({
                            titCell: ".hd ul",//标题栏
                            mainCell: ".bd ul",
                            autoPage: true,
                            effect: "left",//向左滑动
                            autoPlay: true,
                            vis: 4,//可视个数
                            trigger: "click",
                            scroll: 4,//滚动个数
                            interTime: 5000//每次轮播换页,间隔5S
                        });
                    }

                } else {
                }
            } catch (e) {
            }
        }
    })
}


//本文收到的礼物
function gift_show() {
    $.ajax({
        type: 'GET',
        url: url_link + 'gifttemps',
        data: {
            article_id: article_id_details
        },
        async: false,
        success: function (data) {
            try {
                var obj = JSON.parse(data);
                var gift_list = "";
                if (obj.code == 0) {
                    $.each(obj.data, function (i, item) {
                        gift_list += "<li data-gifttemp-id='" + item.gifttemp_id + "' data-name=" + item.name + " data-price=" + item.price + ">" +
                            "<img src=" + item.pic + " style='width: 80px;height: 80px;border-radius: 10px;'>" +
                            "<span><i class='count'>" + item.count + "</i>桶" + item.name + "</span>" +
                            "</li>";
                    });
                    $('.praise-goods-list').html(gift_list);


                } else {

                }
            } catch (e) {
            }
        }
    });
}


//打赏信息展示(界面+弹出框+点赞总数)
function rank_gift() {
    $.ajax({
        type: 'GET',
        url: url_link + 'gifts/rank',
        data: {
            article_id: article_id_details
        },
        async: false,
        success: function (data) {
            try {
                var obj = JSON.parse(data);
                var rank_list = "";//页面上展示出来的打赏
                var rank_list_alert = "";//打赏前三
                var rank_other = "";//打赏第四名开始
                if (obj.code == 0) {
                    //数据显示
                    $.each(obj.data, function (i, item) {
                        if (i == 0) {
                            //排行榜头像链接
                            $('.honor_first a').attr('href', '../lookat/friend.html?user_id=' + item.user.user_id);
                            $('.honor_first a').attr('target', '_blank');

                            //排行榜列表展示
                            $('.honor_first .honor_icon').attr('src', item.user.avatar);
                            $('.honor_first .honor_name').text(item.user.nickname);
                            rank_list = "<span class='honor_award'>赏了<i class='award_goldicon'></i><i class='award_gold'>" + item.money + "</i></span>";
                            $('.honor_first a').append(rank_list);

                            //排行榜弹出框头像链接
                            $('.fir a').attr('href', '../lookat/friend.html?user_id=' + item.user.user_id);
                            $('.fir a').attr('target', '_blank');

                            //排行榜弹出框展示
                            $('.fir img').attr('src', item.user.avatar);
                            $('.fir .user-name').text(item.user.nickname);
                            rank_list_alert = "<span class='user-coins'><i></i>" + item.money + "</span>";
                            $('.fir a').append(rank_list_alert);

                        } else if (i == 1) {
                            //排行榜头像链接
                            $('.honor_second a').attr('href', '../lookat/friend.html?user_id=' + item.user.user_id);
                            $('.honor_second a').attr('target', '_blank');

                            //排行榜列表展示
                            $('.honor_second .honor_icon').attr('src', item.user.avatar);
                            $('.honor_second .honor_name').text(item.user.nickname);
                            rank_list = "<span class='honor_award'>赏了<i class='award_goldicon'></i><i class='award_gold'>" + item.money + "</i></span>";
                            $('.honor_second a').append(rank_list);

                            //排行榜弹出框头像链接
                            $('.sec a').attr('href', '../lookat/friend.html?user_id=' + item.user.user_id);
                            $('.sec a').attr('target', '_blank');

                            //排行榜弹出框展示
                            $('.sec img').attr('src', item.user.avatar);
                            $('.sec .user-name').text(item.user.nickname);
                            rank_list_alert = "<span class='user-coins'><i></i>" + item.money + "</span>";
                            $('.sec a').append(rank_list_alert);

                        } else if (i == 2) {
                            //排行榜头像链接
                            $('.honor_third a').attr('href', '../lookat/friend.html?user_id=' + item.user.user_id);
                            $('.honor_third a').attr('target', '_blank');

                            //排行榜列表展示
                            $('.honor_third .honor_icon').attr('src', item.user.avatar);
                            $('.honor_third .honor_name').text(item.user.nickname);
                            rank_list = "<span class='honor_award'>赏了<i class='award_goldicon'></i><i class='award_gold'>" + item.money + "</i></span>";
                            $('.honor_third a').append(rank_list);

                            //排行榜弹出框头像链接
                            $('.thi a').attr('href', '../lookat/friend.html?user_id=' + item.user.user_id);
                            $('.thi a').attr('target', '_blank');

                            //排行榜弹出框展示
                            $('.thi img').attr('src', item.user.avatar);
                            $('.thi .user-name').text(item.user.nickname);
                            rank_list_alert = "<span class='user-coins'><i></i>" + item.money + "</span>";
                            $('.thi a').append(rank_list_alert);

                        } else {
                            //排行榜弹出框,前三之后的列表
                            rank_other += "<li>" +
                                "<div class='li-box'>" +
                                "<span class='fir'>" + (i + 1) + "</span>" +
                                "<span class='sec'>" +
                                "<a href='../lookat/friend.html?user_id=" + item.user.user_id + "' target='_blank'>" +
                                "<i class='praise-userimg'>" +
                                "<img src=" + item.user.avatar + " style='width: 50px;height: 50px;'>" +
                                "</i>" + item.user.nickname + "</a></span>" +
                                "<span class='thi'>打赏</span>" +
                                "</div>" +
                                "</li>"
                        }
                        if (rank_other) {
                            $('.praise-ranks').html(rank_other);
                        }

                    });
                } else {

                }
            } catch (e) {
            }
        }
    })

}


//用户的金币数展示
function user_gold() {
    $.ajax({
        type: 'GET',
        url: url_link + 'users/' + user_id,
        async: false,
        success: function (data) {
            try {
                var obj = JSON.parse(data);
                if (obj.code == 0) {
                    $('.my-coins b').text(obj.data.gold)
                } else {

                }
            } catch (e) {
            }
        }
    });
}


//评论(上传图片)
function setImagePreview(file, id) {
    $('.loading').show();
    _id = id;
    var _id_name = 'img-box-' + id;
    var prevDiv = document.getElementById(_id_name);
    if (file.files && file.files[0]) {
        var postfix = file.files[0].name.split('.').pop();
        if (postfix != "jpg" && postfix != "gif" && postfix != "png" && postfix != "jpeg") {
            $('.loading').hide();
            layer.msg("上传仅支持：jpg,gif,png,jpeg格式")
        } else {
            var reader = new FileReader();
            reader.onload = function (evt) {
                //上传又拍云
                var ext = '.' + file.files[0].name.split('.').pop();
                var config = {
                    bucket: 'motorcycle',
                    expiration: parseInt((new Date().getTime() + 3600000) / 1000),
                    // 尽量不要使用直接传表单 API 的方式，以防泄露造成安全隐患
                    form_api_secret: '0jWegIsJu9xVxJMrgp4ydONAxok='
                };
                var instance = new Sand(config);
                instance.upload("addComment/" + parseInt((new Date().getTime() + 3600000) / 1000) + ext);
                prevDiv.innerHTML = '<img src=" " style="width: 80px;height: 80px;" id="upload-img-' + id + '">';
            }
            reader.readAsDataURL(file.files[0]);

        }
    } else {
        $('.loading').hide();
    }
}


//获取又拍云图片路径
document.addEventListener('uploaded', function (e) {
    for (var key in e.detail) {
        if (key === 'path') {
            var img_url = '';
            img_url = "http://motorcycle.b0.upaiyun.com" + e.detail[key] + "!/quality/80/fw/500";
            $('#upload-img-' + _id).attr('src', img_url);
            $('.comment-img-area-' + _id).show();
            $('.loading').hide();
        }
    }
});


//热门评论(页面刷新 or 进入页面时加载,确保是否存在user_id)
function article_comments_hot_first() {
    if (user_id) {
        data_motocycle = {
            article_id: article_id_details,
            user_id: user_id
        }
    } else {
        data_motocycle = {
            article_id: article_id_details
        }
    }
    article_comments_hot();

}


//热门评论
function article_comments_hot() {
    $.ajax({
        type: 'GET',
        url: url_link + 'comments',
        data: data_motocycle,
        async: false,
        success: function (data) {
            try {
                var obj = JSON.parse(data);
                var comments_hot = "";
                if (obj.code == 0) {
                    if (obj.data.length == 0) {
                        comments_hot += "<h2 class='none_info'>暂时还没有收到评论哦</h2>"
                    } else {
                        $.each(obj.data, function (i, item) {
                            if (i == obj.data.length - 1) {
                                comments_hot += "<dl class='comment-list' style='border-bottom-style: none;'>"
                            } else {
                                comments_hot += "<dl class='comment-list'>"
                            }
                            comments_hot += "<dt>";
                            if (user_id) {
                                if (user_id == item.user.user_id) {
                                    //自己发表的
                                    comments_hot += "<a href='../center/home.html' class='user' target='_blank'>"
                                } else {
                                    //别人发表的
                                    comments_hot += "<a href='../lookat/friend.html?user_id=" + item.user.user_id + "' class='user' target='_blank'>"
                                }
                            } else {
                                comments_hot += "<a href='../loading.html' class='user' target='_blank'>"
                            }
                            if (!item.user.avatar) {
                                item.user.avatar = "../../image/base/none.png"
                            }
                            comments_hot += "<img src=" + item.user.avatar + " class='img_head'>";
                            if (item.user.sex == 1) {
                                comments_hot += "<b class='male-small' style='position: relative;left: -8px;top: 10px;'></b>"
                            } else {
                                comments_hot += "<b class='female-small' style='position: relative;left: -8px;top: 10px;'></b>"
                            }
                            comments_hot += "<em>" + item.user.nickname + "</em>" +
                                "</a>" +
                                "<span class='create-time'>" + item.createdDate + "</span>" +
                                "<span class='floor'>[ <b>" + item.floor + "</b>楼 ]</span>" +
                                "<a href='javascript:;' class='up-btn' data-comment-id=" + item.comment_id + "><em>" + item.like_count + "</em></a>" +
                                "</dt>" +
                                "<dd class='comment-content'>" +
                                "<p>" + item.content + "</p>";
                            //存在图片
                            if (item.pic_url != undefined) {
                                comments_hot += "<a href='javascript:;' class='comment-imgBox commentImgBox'>" +
                                    "<img src=" + item.pic_url + " style='width: 80px;height: 80px;'>" +
                                    "</a>"
                            }
                            comments_hot += "</dd>";
                            if (user_id) {
                                comments_hot += "<dd class='comment-operate'>"
                                if (user_id == item.user.user_id || is_admin == 1) {
                                    comments_hot += "<a href='javascript:;' class='comment-delete-btn' data-comment-id=" + item.comment_id + ">删除</a> | "
                                }
                                comments_hot += "<a href='javascript:;' class='report-btn' data-report-person-user-id=" + item.user.user_id + ">举报</a> |" +
                                    "<a href='javascript:;' class='reply-btn' data-target-user-id=" + item.user.user_id + " data-target-comment-id=" + item.comment_id + ">回复</a>" +
                                    "</dd>"
                            }
                            comments_hot += "</dl>"
                        });
                    }

                    $('.hot-comment').html(comments_hot);

                } else {

                }
            } catch (e) {
            }
        }
    })
}


//全部评论(页面刷新 or 进入页面时加载,确保是否存在user_id)
function article_comments_all_first() {
    if (user_id) {
        data_motocycle = {
            article_id: article_id_details,
            page: 1,
            rankType: 0,
            user_id: user_id
        }
    } else {
        data_motocycle = {
            article_id: article_id_details,
            page: 1,
            rankType: 0
        }
    }
    article_comments_all();

}


//全部评论
function article_comments_all() {
    $.ajax({
        type: 'GET',
        url: url_link + 'comments',
        data: data_motocycle,
        async: false,
        success: function (data) {
            try {
                var obj = JSON.parse(data);
                var comments_all = "";
                if (obj.code == 0) {
                    $('#thread-comment h2 span').text("(" + obj.data.rows.length + "条)");
                    if (obj.data.rows.length == 0) {
                        comments_all += "<h2 class='none_info'>暂时还没有收到评论哦</h2>"
                    } else {
                        $.each(obj.data.rows, function (i, item) {
                            comments_all += "<dl class='comment-list'><dt>";
                            if (user_id) {
                                if (user_id == item.user.user_id) {
                                    //自己发表的
                                    comments_all += "<a href='../center/home.html' class='user' target='_blank'>"
                                } else {
                                    //别人发表的
                                    comments_all += "<a href='../lookat/friend.html?user_id=" + item.user.user_id + "' class='user' target='_blank'>"
                                }
                            } else {
                                comments_all += "<a href='../loading.html' class='user' target='_blank'>"
                            }
                            if (!item.user.avatar) {
                                item.user.avatar = "../../image/base/none.png"
                            }
                            comments_all += "<img src=" + item.user.avatar + " class='img_head'>";
                            if (item.user.sex == 1) {
                                comments_all += "<b class='male-small' style='position: relative;left: -8px;top: 10px;'></b>"
                            } else {
                                comments_all += "<b class='female-small' style='position: relative;left: -8px;top: 10px;'></b>"
                            }
                            comments_all += "<em>" + item.user.nickname + "</em>" +
                                "</a>" +
                                "<span class='create-time'>" + item.createdDate + "</span>" +
                                "<span class='floor'>[ <b>" + item.floor + "</b>楼 ]</span>" +
                                "<a href='javascript:;' class='up-btn white-button' data-comment-id=" + item.comment_id + ">顶(<em>" + item.like_count + "</em>)</a>" +
                                "</dt>" +
                                "<dd class='comment-content'>"
                            if (item.target_pic){
                                comments_all +="<p style='float:left;width:617px; margin-right:20px;padding-right:10px;border-right:1px solid #eee;min-height:80px;'>"
                            }else{
                                comments_all +="<p>"
                            }
                            comments_all +=item.content + "</p>";
                            //存在图片
                            if (item.pic_url != undefined) {
                                comments_all += "<a href='javascript:;' class='comment-imgBox commentImgBox'>" +
                                    "<img src=" + item.pic_url + " style='width: 80px;height: 80px;'>" +
                                    "</a>"
                            }
                            //对图片评论
                            if (item.target_pic){
                                comments_all +="<a href='javascript:;' class='comment-imgBox commentImgBox' style='float:left'>" +
                                    "<img src="+item.target_pic+" style='width: 80px;height: 80px;'>点击查看原图</a>"
                            }
                            comments_all += "</dd>";
                            if (item.type == 1) {
                                if (item.comment) {
                                    //评论存在
                                    comments_all += "<dl class='quote'>" +
                                        "<dt>" +
                                        "<a href='../lookat/friend.html?user_id=" + item.comment.user.user_id + "' class='head-pic' target='_blank' style='margin-right: 10px;'>"
                                    if (!item.comment.user.avatar) {
                                        item.comment.user.avatar = "../../image/base/none.png"
                                    }
                                    comments_all += "<img src=" + item.comment.user.avatar + " class='img_head'>";
                                    if (item.comment.user.sex == 1) {
                                        comments_all += "<b class='male-small' style='position: relative;left: -8px;top: 10px;'>"
                                    } else {
                                        comments_all += "<b class='female-small' style='position: relative;left: -8px;top: 10px;'>"
                                    }
                                    comments_all += "</b>" + item.comment.user.nickname + "</a>" + item.comment.createdDate + " [ <b>" + item.comment.floor + "</b>楼 ]" +
                                        "</dt>" +
                                        "<dd>" +
                                        "<p style='color: black;'>" + item.comment.content + "</p>";
                                    if (item.comment.pic_url != undefined) {
                                        comments_all += "<a href='javascript:;' class='comment-imgBox'><img src=" + item.comment.pic_url + " style='width: 80px;height: 80px;'></a>"
                                    }

                                    comments_all += "</dd></dl>"
                                } else {
                                    //原评论被删除
                                    comments_all += "<dl class='quote'><p class='comment-deleted'>原评论已被删除</p></dl>"
                                }

                            }
                            if (user_id) {
                                comments_all += "<dd class='comment-operate'>";
                                if (user_id == item.user.user_id || is_admin == 1) {
                                    comments_all += "<a href='javascript:;' class='comment-delete-btn' data-comment-id=" + item.comment_id + ">删除</a> | "
                                }
                                comments_all += "<a href='javascript:;' class='report-btn' data-report-person-user-id=" + item.user.user_id + ">举报</a> | " +
                                    "<a href='javascript:;' class='reply-btn' data-target-user-id=" + item.user.user_id + " data-target-comment-id=" + item.comment_id + ">回复</a></dd>"

                            }
                            comments_all += "</dl>"
                        });
                    }
                    $('.all-comment').html(comments_all);

                } else {

                }
            } catch (e) {
            }
        }
    })
}


//打开打赏排行榜
$(document).on('click', '.reward-rank', function () {
    $('#overlay').show();
});


//关闭打赏排行榜
$(document).on('click', '.praise-box .close', function () {
    $('#overlay').hide();
});


//删除  or  关闭图片盒子
$(document).on('click', '.comment-img-area .close', function () {
    $('#upload-img').attr('src', '');
    $('.comment-img-area').hide();
});


//发表一级评论
$(document).on('click', '#pub-comment-btn', function () {
    $('.loading').show();
    var content_info = $('.comment-textarea').val();
    var pic_url_info = $('#upload-img-0').attr('src');
    reply_type = 0;
    $.ajax({
        type: 'post',
        url: url_link + "comments",
        data: {
            user_id: user_id,
            target_user_id: target_user_id,
            article_id: article_id_details,
            content: content_info,
            pic_url: pic_url_info,
            type: reply_type
        },
        success: function (data) {
            try {
                var obj = JSON.parse(data);
                if (obj.code == 0) {
                    $('.loading').hide();
                    layer.msg("发表成功!");
                    setTimeout(function () {
                        location.reload();
                    }, 1000);

                }
            } catch (e) {
                $('.loading').hide();
                layer.msg(data.msg, {time: 3000});
            }
        }

    })
});


//对评论回复,显示评论盒子
$(document).on('click', '.reply-btn', function () {
    $('.loading').show();
    $('.comment-img-area').hide();
    $('.img-box img').attr('src', '');
    var _target_comment_id = $(this).attr('data-target-comment-id');
    var reply_box = '';
    reply_box += "<div class='reply-box'>" +
        "<textarea placeholder='请发表回复，回复中不要带有侮辱国家或他人的言论。' style='color: black;'></textarea>" +
        "<div class='button-box' style='position: relative;'>" +
        "<a href='javascript:;' id='reply-pickfiles' class='upload-img-btn'><i></i>发图片</a> " +
        "<a href='javascript:;' id='pub-reply' class='blue-button' data-target-comment-id=" + _target_comment_id + ">回复评论</a>" +
        "<input type='file' name='file' id='file_" + _target_comment_id + "' multiple='multiple' onchange='setImagePreview(this," + _target_comment_id + ");'" +
        "style='width: 60px;position: absolute;margin-left: -155px;height: 40px;opacity: 0;'>" +
        "<div class='comment-img-area comment-img-area-" + _target_comment_id + "' style='left: 564.562px; margin-top: 10px;display: none;'>" +
        "<div class='comment-img-box'>" +
        "<span>" +
        "<em></em>" +
        "<b></b>" +
        "</span>" +
        "<a href='javascript:;' class='close'>×</a>" +
        "<div class='img-box' id='img-box-" + _target_comment_id + "'></div>" +
        "</div>" +
        "</div>" +
        "</div></div></div>";
    var m = $(this).parent().parent('.comment-list');
    if (!m.find('.reply-box').html()) {
        m.append(reply_box)
    }
    $('.loading').hide();
});


//对评论回复,发送评论
$(document).on('click', '#pub-reply', function () {
    $('.loading').show();
    var _target_comment_id = $(this).attr('data-target-comment-id');
    var _content = $(this).parent().parent('.reply-box').children('textarea').val();
    var _pic_url = $(this).parent('.button-box').find('img').attr('src');
    reply_type = 1;
    $.ajax({
        type: 'post',
        url: url_link + "comments",
        data: {
            user_id: user_id,
            target_user_id: target_user_id,
            article_id: article_id_details,
            content: _content,
            pic_url: _pic_url,
            target_comment_id: _target_comment_id,
            type: reply_type
        },
        success: function (data) {
            try {
                var obj = JSON.parse(data);
                if (obj.code == 0) {
                    $('.loading').hide();
                    layer.msg("发表成功!");
                    setTimeout(function () {
                        location.reload();
                    }, 1000);
                }
            } catch (e) {

            }
        }

    })
});


//评论排序
$(document).on('click', '.comment-order a', function () {
    $('.loading').show();
    var _html = $(this).html();
    $('.comment-order a').removeClass('current')
    $(this).addClass('current');
    if (_html == "最新") {
        if (user_id) {
            data_motocycle = {
                article_id: article_id_details,
                page: 1,
                rankType: 0,
                user_id: user_id
            }
        } else {
            data_motocycle = {
                article_id: article_id_details,
                page: 1,
                rankType: 0
            }
        }
    } else if (_html == "最旧") {
        if (user_id) {
            data_motocycle = {
                article_id: article_id_details,
                page: 1,
                rankType: 1,
                user_id: user_id
            }
        } else {
            data_motocycle = {
                article_id: article_id_details,
                page: 1,
                rankType: 1
            }
        }
    } else if (_html == "最热") {
        if (user_id) {
            data_motocycle = {
                article_id: article_id_details,
                page: 1,
                rankType: 2,
                user_id: user_id
            }
        } else {
            data_motocycle = {
                article_id: article_id_details,
                page: 1,
                rankType: 2
            }
        }
    }

    article_comments_all();
    $('.loading').hide();

});


//打赏
$(document).on('click', '.praise-goods-list li', function () {
    var _name = $(this).attr('data-name');
    var _price = $(this).attr('data-price');
    var _id = $(this).attr('data-gifttemp-id');
    layer.msg('您真的要打赏给Ta一桶' + _name + '吗?这将花费您' + _price + '金币', {
        time: 0, //不自动关闭
        btn: ['确定', '取消'],
        yes: function (index) {
            $('.loading').show();
            layer.close(index);
            $.ajax({
                type: 'POST',
                url: url_link + 'gifts',
                data: {
                    user_id: user_id,
                    article_id: article_id_details,
                    gifttemp_id: _id,
                    count: 1
                },
                async: false,
                success: function (data) {
                    try {
                        var obj = JSON.parse(data);
                        if (obj.code == 0) {
                            $('.loading').hide();
                            layer.msg("打赏成功!");
                            setTimeout(function () {
                                location.reload();
                            }, 3000)
                        }
                    } catch (e) {
                        $('.loading').hide();
                        layer.msg(data.msg, {time: 3000});
                    }

                }
            })
        }
    });
});


//收藏  or  取消收藏
$(document).on('click', '.collect a', function () {
    var m = $(this);
    if (m.hasClass('has-favorite')) {
        //已收藏,现在要取消收藏
        layer.msg('真的要取消收藏该文章吗？', {
            time: 0, //不自动关闭
            btn: ['确定', '取消'],
            yes: function (index) {
                layer.close(index);
                $.post(url_link + 'articlesaves', {
                    user_id: user_id,
                    article_id: article_id_details
                }, function (data) {
                    var obj = JSON.parse(data);
                    if (obj.code == 0) {
                        m.removeClass('has-favorite');
                        m.addClass('add-favorite');
                    }
                })
            }
        });
    } else {
        //收藏文章
        $.post(url_link + 'articlesaves', {
            user_id: user_id,
            article_id: article_id_details
        }, function (data) {
            var obj = JSON.parse(data);
            if (obj.code == 0) {
                m.removeClass('add-favorite');
                m.addClass('has-favorite');
            }
        })
    }

});


//对文章点赞
$(document).on('click', '.praise-thread-btn', function () {
    $.post(url_link + 'articlelikes', {
        user_id: user_id,
        article_id: article_id_details
    }, function (data) {
        try {
            var obj = JSON.parse(data);
            if (obj.code == 0) {
                layer.msg("点赞成功!");
                setTimeout(function () {
                    location.reload()
                }, 1000)
            }
        } catch (e) {
            layer.msg(data.msg, {time: 3000});
        }

    })
});


//对评论点赞
$(document).on('click', '.up-btn', function () {
    var comment_id_info = $(this).attr('data-comment-id');
    $.post(url_link + 'commentlikes', {
        user_id: user_id,
        comment_id: comment_id_info
    }, function (data) {
        try {
            var obj = JSON.parse(data);
            if (obj.code == 0) {
                layer.msg("点赞成功!");
                setTimeout(function () {
                    location.reload()
                }, 1000)
            } else {
                layer.msg("您已经点赞过该评论!");
            }
        } catch (e) {
            layer.msg("您已经点赞过该评论!");
        }

    })
});


//删除评论
$(document).on('click', '.comment-delete-btn', function () {
    var comment_id_info = $(this).attr('data-comment-id');
    layer.msg('您真的要删除这条评论吗？', {
        time: 0, //不自动关闭
        btn: ['确定', '取消'],
        yes: function (index) {
            layer.close(index);
            $.ajax({
                type: 'DELETE',
                url: url_link + 'comments/' + comment_id_info,
                success: function (data) {
                    var obj = JSON.parse(data);
                    if (obj.code == 0) {
                        layer.msg("删除成功!");
                        setTimeout(function () {
                            location.reload()
                        }, 1000)
                    } else {
                        layer.msg(obj.msg);
                    }
                }
            })

        }
    });
});


//删除本文
$(document).on('click', '.delete-article', function () {
    var del_id = $(this).attr('data-id');
    layer.msg('您真的要删除本文吗？', {
        time: 0, //不自动关闭
        btn: ['确定', '取消'],
        yes: function (index) {
            layer.close(index);
            if (del_id == user_id) {
                //自己是管理员,删除自己的文章
                $.ajax({
                    type: 'DELETE',
                    url: url_link + 'articles/' + article_id_details,
                    success: function (data) {
                        try {
                            var obj = JSON.parse(data);
                            if (obj.code == 0) {
                                layer.msg("删除成功!");
                                setTimeout(function () {
                                    window.location.href = "../../index.html"
                                }, 1000)
                            } else {
                                layer.msg(obj.msg);
                            }
                        } catch (e) {
                            layer.msg(data.msg);
                        }

                    }
                });
            } else {
                $.ajax({
                    type: 'DELETE',
                    url: url_link + 'articles/admindelete?article_id=' + article_id_details,
                    async: false,
                    success: function (data) {
                        try {
                            var obj = JSON.parse(data);
                            if (obj.code == 0) {
                                layer.msg("删除成功!");
                                setTimeout(function () {
                                    window.location.href = "../../index.html"
                                }, 1000)
                            } else {
                                layer.msg(obj.msg);
                            }
                        } catch (e) {
                            layer.msg(data.msg);
                        }

                    }
                });
            }


        }
    });


});


//修改主题按钮
$(document).on('click', '.change_theme', function () {
    $.get(url_link + 'themes', function (data) {
        try {
            var obj = JSON.parse(data);
            var interest_list = "";
            if (obj.code == 0) {
                interest_list += "<span><em></em><i></i></span><a href='javascript:;' class='remove'>×</a></li>";
                $.each(obj.data, function (i, item) {
                    interest_list += "<li><a href='javascript:;' data-theme-id=" + item.theme_id + ">" + item.name + "</a></li>"
                });
                $('.interest-list-theme').html(interest_list);
                $('.interest-list-theme').show();
            }
        } catch (e) {
        }
    })
});


//显示具体主题
$(document).on('click', '.interest-list-theme li', function () {
    var _text = $(this).children('a').html();
    var _theme_id = $(this).children('a').attr('data-theme-id');
    layer.msg('您确定要将主题,修改为' + _text + '吗?', {
        time: 0, //不自动关闭
        btn: ['确定', '取消'],
        yes: function (index) {
            layer.close(index);
            data_motocycle = {
                article_id: article_id_details,
                theme_id: _theme_id
            };
            change_info();
        }
    });
});


//修改车型按钮
$(document).on('click', '.change_mototype', function () {
    $.get(url_link + 'mototypes', function (data) {
        try {
            var obj = JSON.parse(data);
            var interest_list = "";
            if (obj.code == 0) {
                interest_list += "<span><em></em><i></i></span><a href='javascript:;' class='remove'>×</a></li><div class='interest-list-mototype-show'>";
                $.each(obj.data, function (i, item) {
                    interest_list += "<li><a href='javascript:;' data-mototype-id=" + item.mototype_id + ">" + item.name + "</a></li>"
                });
                interest_list += "</div>"
                $('.interest-list-mototype').html(interest_list);
                $('.interest-list-mototype').show();
            }
        } catch (e) {
        }
    })
});


//显示具体车型
$(document).on('click', '.interest-list-mototype li', function () {
    var _text = $(this).children('a').html();
    var _mototype_id = $(this).children('a').attr('data-mototype-id');
    layer.msg('您确定要将车型,修改为' + _text + '吗?', {
        time: 0, //不自动关闭
        btn: ['确定', '取消'],
        yes: function (index) {
            layer.close(index);
            data_motocycle = {
                article_id: article_id_details,
                mototype_id: _mototype_id
            };
            change_info();
        }
    });
});


//提交修改,令管理员可以修改主题或车型
function change_info() {
    $.post(url_link + 'articles/adminSet', data_motocycle, function (data) {
        var obj = JSON.parse(data);
        if (obj.code == 0) {
            $('.interest-list-mototype').hide();
            $('.interest-list-theme').hide();
            layer.msg("修改成功!");
            setTimeout(function () {
                location.reload()
            }, 1000)
        }
    })
}


//修改主题或车型时的关闭按钮
$(document).on('click', '.interest-list .remove', function () {
    $(this).parent().hide();
});


//点击查看文章大图
$(document).on('click', '.img_link', function () {
    $('#show_big_img').show();
    img_src = $(this).attr('data-url');

    img_link = $(this).children('canvas')

    var mycanvas = document.createElement('canvas');
    document.getElementById('show_big_img').appendChild(mycanvas);

    img_width = img_link.css('width');//图片真实宽度
    img_width = img_width.substring(0, img_width.length - 2);

    img_height = img_link.css('height');//图片真实高度
    img_height = img_height.substring(0, img_height.length - 2);


    div_width = $('#show_big_img').css('width');//屏幕高度
    div_width = div_width.substring(0, div_width.length - 2);

    div_height = $('#show_big_img').css('height');//屏幕高度
    div_height = div_height.substring(0, div_height.length - 2);


    if (img_width >= img_height) {
        mycanvas.width = div_height * 0.6 * img_width / img_height;//canvas的宽度
        mycanvas.height = div_height * 0.6;//canvas的高度

        $('#show_big_img canvas').css('margin-top', '10%');
        $('#show_big_img canvas').css('margin-left', (div_width - mycanvas.width) / 2);
    } else {

        mycanvas.width = div_width * 0.3;//canvas的宽度
        mycanvas.height = div_width * 0.3 * img_height / img_width;//canvas的高度

        $('#show_big_img canvas').css('margin-top', (div_height - mycanvas.height) / 2);
        $('#show_big_img canvas').css('margin-left', '35%');

    }


    change_canvas(mycanvas)

});


//点击查看评论大图
$(document).on('click', '.commentImgBox', function () {
    $('#show_big_img').show();
    img_src = $(this).children('img').attr('src');

    img_link = $(this).children('img');

    $(this).children('img').css('width', 'auto')

    var mycanvas = document.createElement('canvas');
    document.getElementById('show_big_img').appendChild(mycanvas);

    img_width = img_link.css('width');//图片真实宽度
    img_width = img_width.substring(0, img_width.length - 2);

    img_height = 80; //评论时图片高度被定死

    div_width = $('#show_big_img').css('width');//屏幕高度
    div_width = div_width.substring(0, div_width.length - 2);

    div_height = $('#show_big_img').css('height');//屏幕高度
    div_height = div_height.substring(0, div_height.length - 2);

    if (img_width >= img_height) {
        mycanvas.width = div_height * 0.6 * img_width / img_height;//canvas的宽度
        mycanvas.height = div_height * 0.6;//canvas的高度

        $('#show_big_img canvas').css('margin-top', '10%');
        $('#show_big_img canvas').css('margin-left', (div_width - mycanvas.width) / 2);
    } else {
        mycanvas.width = div_width * 0.3;//canvas的宽度
        mycanvas.height = div_width * 0.3 * img_height / img_width;//canvas的高度

        $('#show_big_img canvas').css('margin-top', (div_height - mycanvas.height) / 2);
        $('#show_big_img canvas').css('margin-left', '35%');

    }

    change_canvas(mycanvas);

    $(this).children('img').css('width', '80px')
});


//关闭大图
$(document).on('click', '#show_big_img', function () {
    $(this).hide();
    $(this).children('canvas').remove();
});


//canvas画图
function change_canvas(canvas) {
    var data = {
        image: [img_src, "../../image/base/logowater.png"]
    };
    var len = data.image.length;

    if (canvas.getContext) {
        var context = canvas.getContext('2d');
        // 宣传图片
        function drawing(num) {
            if (num < len) {
                var img = new Image;
                img.src = data.image[num];
                if (num == 0) {
                    //背景图
                    img.onload = function () {
                        context.drawImage(img, 0, 0, canvas.width, canvas.height);
                        drawing(num + 1);
                    }
                } else if (num == 1) {
                    //头像
                    img.onload = function () {
                        context.drawImage(img, canvas.width * 0.4, canvas.height - canvas.width * 0.014 - 5, canvas.width * 0.2, canvas.width * 0.014);
                        drawing(num + 1);
                    }
                }
            }
        }

        drawing(0);
    }
}


//打开图片评论弹框
$(document).on('click','.thread-image-comment-btn',function(){
    $('.img-comment-overlay').show();
    $('.img-comment-overlay .img-comment-box').css('height',window.screen.height*0.6+'px');

    var _url=$(this).parents('.img-box').children('.img_link').attr('data-url');
    var _height=$(this).parents('.img-box').find('canvas').attr('height');
    $('.img-comment-overlay .img-comment img').attr('src',_url);
    var _height_new=_height/1.12;
    if(_height_new>500){
        $('.img-comment-overlay .img-comment img').css('height','500px');
        var _width_new=500*728/_height;
        $('.img-comment-overlay .img-comment img').css({marginLeft:(690-_width_new)/2+'px',marginRight:(690-_width_new)/2+'px'});

    }else{
        $('.img-comment-overlay .img-comment img').css('width','650px');
        $('.img-comment-overlay .img-comment img').css('margin','0 20px');

    }
});



//关闭图片评论弹框
$(document).on('click','.close-img-comment',function(){
    $('.img-comment-overlay').hide();
    $('.img-comment-overlay .img-comment img').css('height','auto');
    $('.img-comment-overlay .img-comment img').css('width','auto');
    $('.img-comment-overlay .img-comment img').attr('src','');

});


//对图片发表评论
$(document).on('click', '#pub-img-comment-btn', function () {
    $('.loading').show();
    var content_info = $('.img-comment-input textarea').val();
    var target_pic_info = $('.img-comment img').attr('src');
    reply_type = 2;
    $.ajax({
        type: 'post',
        url: url_link + "comments",
        data: {
            user_id: user_id,
            target_user_id: target_user_id,
            article_id: article_id_details,
            content: content_info,
            target_pic: target_pic_info,
            type: reply_type
        },
        success: function (data) {
            try {
                var obj = JSON.parse(data);
                if (obj.code == 0) {
                    $('.loading').hide();
                    layer.msg("发表成功!");
                    setTimeout(function () {
                        location.reload();
                    }, 1000);

                }
            } catch (e) {
                $('.loading').hide();
                layer.msg(data.msg, {time: 3000});
            }
        }

    })
});

